<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>新经资讯后台管理</title>
	<link rel="stylesheet" type="text/css" href="../../static/admin/css/reset.css">
	<link rel="stylesheet" type="text/css" href="../../static/admin/css/main.css">
	<link rel="stylesheet" href="../../static/admin/css/jquery.pagination.css">
	<script type="text/javascript" src="../../static/admin/js/jquery-1.12.4.min.js"></script>
	<script type="text/javascript" src="../../static/admin/js/jquery.pagination.min.js"></script>
</head>
<body>
	<div class="breadcrub">
        当前位置：新闻管理>新闻版式编辑
		<form class="news_filter_form">
			<input type="text" placeholder="请输入关键字" class="input_txt" name="keywords">
			<input type="submit" value="搜 索" class="input_sub">
		</form>
	</div>
		

	<div class="pannel">			
        <table class="common_table">
            <tr>
                <th width="5%">id</th>
                <th width="50%">标题</th>
                <th width="10%">点击数</th>
                <th width="15%">发布时间</th>
                <th width="10%">编辑</th>
                <th width="10%">删除</th>
            </tr>
            {% for news in data.news_list %}
                <tr>
                    <td>{{ news.id }}</td>
                    <td class="tleft">
                        <a href="/news/{{ news.id }}" target="_blank">{{ news.title }}</a>
                    </td>
                    <td>{{ news.clicks }}</td>
                    <td>{{ news.create_time }}</td>
                    <td>
                        <a href="{{ url_for('admin.news_edit_detail') }}?news_id={{ news.id }}" class="edit">编辑</a>
                    </td>
                    <td>
                        <a href="javascript:;" class="delete">删除</a>
                    </td>
                </tr>
            {% endfor %}
        </table>
    </div>
		
    <div class="box">
        <div id="pagination" class="page"></div>
    </div>

    <script>
        $(function() {
            $("#pagination").pagination({
                currentPage: {{ data.current_page }},
                totalPage: {{ data.total_page }},
                callback: function(current) {
                    window.location.href = '/admin/news_edit?p=' + current
                }
            });
        });
        $('.delete').click(function () {
                //获取删除新闻id
                var news_id = $(this).parent().siblings(0).html();
                var params = {"news_id": news_id};
                $.ajax({
                    url: "/admin/delete_news",
                    method: "post",
                    headers: {"X-CSRFToken": getCookie("csrf_token")},
                    data: JSON.stringify(params),
                    contentType: "application/json",
                    success: function (resp) {
                        if (resp.errno == "0") {
                            // 刷新当前界面
                            location.reload();
                        }else {
                            alert(resp.errmsg)
                        }
                    }
                })
            });
        function getCookie(name) {
            var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
            return r ? r[1] : undefined;
        }
    </script>
</body>
</html>